package com.gagakuai.bpm.config.redis;

import com.alibaba.fastjson.JSON;

import com.gagakuai.bpm.domian.dto.camunda.UserInfo;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Repository;

import javax.annotation.Resource;
import java.util.concurrent.TimeUnit;

/*
 * 登录缓存
 */
@Repository
public class TokenRepository {

    @Resource
    private RedisTemplate redisTemplate;

//    public final static String BPM_TOKEN = "{bpm.token}:";

    /*
     * 保存用户信息
     */
    public void set(String token, UserInfo userInfo) {
        redisTemplate.opsForValue().set(token, userInfo, 120, TimeUnit.MINUTES);
    }

    /*
     * 获取用户登录信息
     *
     * @param token 登录标识
     * @return 登录信息
     */
    public UserInfo get(String token) {
        String s = (String) redisTemplate.opsForValue().get(token);

        return JSON.parseObject(s, UserInfo.class);
    }
}
